var parameter= "";
$(function(){
	Chart.defaults.global.defaultFontColor = '#fff';
	var customer =GetQueryString("customer");
	var routename=decodeURIComponent(window.atob(customer));
	$(".alltitle").html(routename);
	parameter= {"startTime":"2017-01-01","customer":routename}
	//客户分析，按货类
	customerAnalysis_cargo();
	//客户分析，按航线
	customerAnalysis_route();
	//客户分析，月度箱量趋势 
	customerAnalysis_MonthlyBoxVolumeTrends();
	//客户分析，月TEU平均运价 
	customerAnalysis_MonthlyTEUAverageFreight();
})
//客户分析，月TEU平均运价 
var customerAnalysis_MonthlyTEUAverageFreight =function(){
	$.ajax({
	    type: "post",
	    async: true,
	    url: "/enReport/customerAnalysis_MonthlyTEUAverageFreight",
	    data: parameter,
	    dataType: "json",
	    success: function(data){
	    	var labels4=[];
	    	var data4=[];
	    	for(var i=0;i<data.length;i++){
 	    		labels4.push(data[i].month);
 	    		data4.push(data[i].avgyj);
	    	}
 			var customer_4 = document.getElementById('customer_4').getContext('2d');	
			var myChartcustomer_4 = new Chart(customer_4, {
				type: 'line',
				data: {
					labels: labels4,
					datasets: [{
						label: "数据一",
						borderWidth: '3',
						backgroundColor: [
							"rgba(210,72,91,0.5)",
						],
						borderColor: [
							"rgba(210,72,91,1)",
						],
						pointBackgroundColor: "#46ffc3",
						pointStrokeColor: "#fff",
						data: data4
					}]
				},
				options: {
					maintainAspectRatio: true,
					scales: {
				        xAxes: [{
				            ticks: {
				            	autoSkip: false,
				            }
				        }]
				    },
					legend: {
						labels: {
							
						},
						display: false,
					},
				},
			});
		}
	})
}


//客户分析，月度箱量趋势 
var customerAnalysis_MonthlyBoxVolumeTrends =function(){
		$.ajax({
	    type: "post",
	    async: true,
	    url: "/enReport/customerAnalysis_MonthlyBoxVolumeTrends",
	    data: parameter,
	    dataType: "json",
	    success: function(data){
	    	var labels3=[];
	    	var dara3=[];
	    	for(var i=0;i<data.length;i++){
	    		labels3.push(data[i].month);
	    		dara3.push(data[i].teu);
	    	}
 			var customer_3 = document.getElementById('customer_3').getContext('2d');	
			var myChartcustomer_3 = new Chart(customer_3, {
				type: 'line',
				data: {
					labels: labels3,
					datasets: [{
						label: "teu",
						borderWidth: '3',
						backgroundColor: "rgba(94,151,200,0.5)",
						borderColor: "rgba(94,151,200,1)",
						pointBackgroundColor: "#46ffc3",
						pointStrokeColor: "#fff",
						data: dara3
					}]
				},
				options: {
					maintainAspectRatio: true,
					scales: {
				        xAxes: [{
				            ticks: {
				            	autoSkip: false,
				            }
				        }]
				    },
					legend: {
						labels: {
							
						},
						display: false,
					},
				},
			});
		}
	})
}
//客户分析，按航线
var customerAnalysis_route = function(){
	$.ajax({
	    type: "post",
	    async: true,
	    url: "/enReport/customerAnalysis_route",
	    data: parameter,
	    dataType: "json",
	    success: function(data){
	    	var labels2=[];
	    	var data2=[];
	    	for(var i=0;i<data.length;i++){
	    		labels2.push(data[i].service);
	    		data2.push(data[i].teu);
	    	}
 			var customer_2 = document.getElementById('customer_2').getContext('2d');	
			var myChartcustomer_2 = new Chart(customer_2, {
				type: 'bar',
				data: {
					labels: labels2,
					datasets: [{
						label: "teu",
						borderWidth: '3',
						backgroundColor: [
							"rgba(25,198,198,0.5)",
							"rgba(202,127,50,0.5)",
							"rgba(94,151,200,0.5)",
							"rgba(210,72,91,0.5)",
							"rgba(206,120,222,0.5)",
							"rgba(94,151,200,0.5)"
						],
						borderColor: [
							"rgba(25,198,198,1)",
							"rgba(202,127,50,1)",
							"rgba(94,151,200,1)",
							"rgba(210,72,91,1)",
							"rgba(206,120,222,1)",
							"rgba(94,151,200,1)"
						],
						pointBackgroundColor: "#46ffc3",
						pointStrokeColor: "#fff",
						data:data2
					}]
				},
				options: {
					maintainAspectRatio: true,
					scales: {
				        xAxes: [{
				            ticks: {
				            	autoSkip: false,
				            }
				        }]
				    },
					legend: {
						labels: {
							
						},
						display: false,
					},
				},
			});
		}
	})
}
//客户分析，按货类
var customerAnalysis_cargo= function(){
	$.ajax({
	    type: "post",
	    async: true,
	    url: "/enReport/customerAnalysis_cargo",
	    data: parameter,
	    dataType: "json",
	    success: function(data){
	    	var str="";
	      	for(var i=0 ; i<data.length;i++){
	      		str+='<li><p class="goodsname">'+data[i].gt+'</p><p class="goodsacount">'+data[i].teu+'</p></li>'
	      	}
	      	$("#route_goods").html(str);
		}
	})
}
//截取字符串
function GetQueryString(name){
 	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return  unescape(r[2]); return null;
}